package com.zhong.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhong.blog.mapper.EssayMapper;
import com.zhong.blog.pojo.Essay;
import com.zhong.blog.service.EssayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EssayServiceImpl implements EssayService {
    @Autowired
    EssayMapper essayMapper;
    @Override
    public void save(Essay essay) {
        essayMapper.insert(essay);
    }

    @Override
    public List<Essay> queryAll(int page, int size) {
        QueryWrapper<Essay> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("create_time");
        Page<Essay> essayPage = new Page<>(page,size);
        essayMapper.selectPage(essayPage, wrapper);
        List<Essay> essays = essayPage.getRecords();
        return essays;
    }

}
